Skip to content

Refactor supergroup to TypeScript Vue.js composables with full type safety and generic inference#21

Draft
Copilot wants to merge 7 commits intomasterfrom
copilot/refactor-supergroup-function
Draft

Refactor supergroup to TypeScript Vue.js composables with full type safety and generic inference#21
Copilot wants to merge 7 commits intomasterfrom
copilot/refactor-supergroup-function

Conversation

Copy link

Copilot AI commented Jan 20, 2026

Modernizes supergroup for Vue.js applications by providing reactive composables with full TypeScript support and generic type inference, while preserving the legacy lodash mixin API.

Architecture

New Composables (src/composables/ - TypeScript)

  • useGrouping - Core reactive grouping with auto-update on data changes
  • useGroupList - List operations (lookup, tree navigation, D3 conversion)
  • useGroupValue - Value operations (paths, aggregates, siblings)
  • useGroupSelection - Non-mutating state management

TypeScript Features

  • Full generic type inference - return types automatically match input data types
  • Compile-time type checking for dimension field names
  • Complete .d.ts type definitions exported
  • 175 lines of comprehensive type definitions in src/types.ts

Module Strategy

  • TypeScript source in src/ compiled to ES modules in dist/
  • Legacy supergroup.cjs for CommonJS compatibility
  • Dual exports in package.json support both seamlessly
  • Type definitions included for full IDE support

Usage

// Vue 3 composables with TypeScript (new)
import { ref } from 'vue';
import { useGrouping, useGroupSelection } from 'supergroup/composables';

interface Employee {
  name: string;
  department: string;
  salary: number;
}

const data = ref<Employee[]>([...]);

// Generic type inference - fully typed to Employee!
const { grouped, lookup, leafNodes } = useGrouping(data, ['department', 'name']);
const selection = useGroupSelection(grouped);

// Type-safe - TypeScript validates field names at compile time
const dept = lookup('Engineering'); // Type: GroupValue<Employee> | undefined
// Legacy API (unchanged)
const _ = require('supergroup');
const groups = _.supergroup(data, ['category', 'subcategory']);

Backward Compatibility

  • All 30 existing tests pass unchanged
  • Legacy API completely untouched
  • No breaking changes
  • JavaScript users can use the library without TypeScript

Testing

  • 43/43 tests passing (30 legacy + 13 new)
  • TypeScript compilation: ✅ No errors
  • CodeQL: 0 vulnerabilities
  • Reactivity verified across all composables
  • Type definitions validated

Documentation

  • COMPOSABLES.md - Full API reference with TypeScript examples
  • examples/VueComponent.vue - Working example
  • README.md - Updated with TypeScript usage examples
  • Complete type exports for all public APIs
Original prompt

Refactor the supergroup function to be a modular, reactive utility suitable for use as a composable (or set of composables) in a vue.js application.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits January 20, 2026 14:57
Co-authored-by: bkoplin <17945159+bkoplin@users.noreply.github.com>
Co-authored-by: bkoplin <17945159+bkoplin@users.noreply.github.com>
Co-authored-by: bkoplin <17945159+bkoplin@users.noreply.github.com>
Co-authored-by: bkoplin <17945159+bkoplin@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor supergroup function for modular reactive utility Refactor supergroup to Vue.js composables with dual module support Jan 20, 2026
Copilot AI requested a review from bkoplin January 20, 2026 15:11
@bkoplin
Copy link
Collaborator

bkoplin commented Jan 20, 2026

@copilot please make this a typescript library and strongly type the modules. The return types should vary by the type of the iterable passed to the composables.

Co-authored-by: bkoplin <17945159+bkoplin@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 20, 2026

@copilot please make this a typescript library and strongly type the modules. The return types should vary by the type of the iterable passed to the composables.

Done! The library is now fully TypeScript with strong typing and generic type inference.

What was added:

  • Complete TypeScript conversion of all modules (4 composables + utilities)
  • Generic types that automatically infer from your data: useGrouping<MyRecord>(data, 'field')
  • Type-safe dimension checking - compile errors for invalid field names
  • Full .d.ts type definitions exported
  • 175 lines of comprehensive type definitions in src/types.ts

Type inference example:

interface Employee { name: string; dept: string; salary: number; }
const data = ref<Employee[]>([...]);
const grouping = useGrouping(data, 'dept');
// grouping is typed as UseGroupingReturn<Employee>
// All return values know about Employee structure!

All tests passing (43/43). See commit e402111 for the full TypeScript implementation.

Copilot AI changed the title Refactor supergroup to Vue.js composables with dual module support Refactor supergroup to TypeScript Vue.js composables with full type safety and generic inference Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants